package dao

import (
	"genealogy/models"
)

func GetAllBiography(Biography map[string]interface{}) (error, []models.Biography, int64) {
	var BiographyData []models.Biography
	page := Biography["page"].(int)
	pageSize := Biography["limit"].(int)
	searchName := Biography["searchName"].(string)
	var total int64
	err := db.Table("biographies").Select("person_name, biographies_no, biography, honors_record, update_time").Where("person_name like ? and is_del = false", searchName+"%").Order("biographies_no ASC").Count(&total).Offset((page - 1) * pageSize).Limit(pageSize).Find(&BiographyData).Error
	return err, BiographyData, total
}
func DelBiography(id string) error {
	err := db.Table("biographies").Where("biographies_no = ?", id).Update("is_del", true).Error
	return err
}

func UpdateBiography(Biography models.Biography) error {
	err := db.Table("biographies").Where("biographies_no = ?", Biography.BiographyNo).Updates(&Biography).Error
	return err
}

func AddBiography(Biography models.Biography) error {
	err := db.Table("biographies").Select("person_name", "biographies_no", "biography", "honors_record", "update_time", "is_del").Create(&Biography).Error
	return err
}
